package com.atguigu.gmall.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

/**
 * @author mqx
 * @date 2020-10-24 10:38:28
 */
@Configuration
public class DelayedMqConfig {

    //  定义变量
    public static final String exchange_delay = "exchange.delay";
    public static final String routing_delay = "routing.delay";
    public static final String queue_delay_1 = "queue.delay.1";

    //  只有一个交换机，一个路由键，一个队列
    @Bean
    public CustomExchange delayExchange(){
        //  声明一个map
        HashMap<String, Object> map = new HashMap<>();
        //  设置参数
        map.put("x-delayed-type","direct");
        //  创建对象 第二个参数是固定值：基于插件的配置
        return new CustomExchange(exchange_delay,"x-delayed-message",true,false,map);
    }

    @Bean
    public Queue delayQeue1(){
        //  创建一个对象
        return new Queue(queue_delay_1,true,true,false,null);
    }

    @Bean
    public Binding delayBbinding1(){

        //  返回一个Binding
        //  BindingBuilder.bind(queue1()).to(exchange()).with(routing_dead_1)
        //  BindingBuilder.GenericArgumentsConfigurer with = BindingBuilder.bind(delayQeue1()).to(delayExchange()).with(routing_delay);
        return BindingBuilder.bind(delayQeue1()).to(delayExchange()).with(routing_delay).noargs();
    }


}
